package com.hsnn.medstgmini.sys.service.impl;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.base.dict.dao.DicAreaDao;
import com.hsnn.medstgmini.base.dict.dao.DicCompTypeDao;
import com.hsnn.medstgmini.base.dict.dao.DicHosptypeDao;
import com.hsnn.medstgmini.base.std.dao.StdCompgroupDao;
import com.hsnn.medstgmini.base.std.dao.StdHospInfoDao;
import com.hsnn.medstgmini.sys.dao.SysUserRegisterDao;
import com.hsnn.medstgmini.sys.model.RegCompInfo;
import com.hsnn.medstgmini.sys.model.RegHospInfo;
import com.hsnn.medstgmini.sys.service.SysUserRegisterManager;

@Service
public class SysUserRegisterManagerImpl implements SysUserRegisterManager {

	@Autowired
	private SysUserRegisterDao userRegisterDao;

	@Autowired
	private DicAreaDao areaDao;

	@Autowired
	private DicHosptypeDao hospTypeDao;

	@Autowired
	private DicCompTypeDao compTypeDao;

	@Autowired
	private StdHospInfoDao hospInfoDao;
	
	@Autowired
	private StdCompgroupDao stdCompgroupDao;
       
	/**
	 * @category 保存医疗机构注册信息
	 * @date 2015年6月23日
	 * @param hospInfo
	 */
	@Transactional
	public void saveRegHospInfo(RegHospInfo hospInfo) {
		if (hospInfo != null) {
			if (hospInfo.getArea() != null) {
				String areaid = hospInfo.getArea().getAreaid();
				hospInfo.setArea(areaDao.getDicAreaById(areaid));
			}
			if (hospInfo.getHosptype() != null) {
				String id = hospInfo.getHosptype().getHospTypeId();
				hospInfo.setHosptype(hospTypeDao.findById(id));
			}
			userRegisterDao.saveRegHospInfo(hospInfo);
		}
	}

	/**
	 * @category 保存企业注册信息
	 * @date 2015年6月23日
	 * @param compInfo
	 */
	@Transactional
	public void saveRegCompInfo(RegCompInfo compInfo) {
		if (compInfo != null) {
			if(compInfo.getCompGroupName() != null){
				String compGroupId = compInfo.getCompGroupName().getCompGroupId();
				compInfo.setCompGroupName(stdCompgroupDao.getById(compGroupId));
			}
			if (compInfo.getArea() != null) {
				String areaid = compInfo.getArea().getAreaid();
				compInfo.setArea(areaDao.getDicAreaById(areaid));
			}
			if (compInfo.getCompReg() != null) {
				String id = compInfo.getCompReg().getCompRegId();
				compInfo.setCompReg(compTypeDao.getDicCompTypeById(id));
			}
			userRegisterDao.saveRegCompInfo(compInfo);
		}
	}

	
}
